﻿using UnityEngine;
using System.Collections;
using JsonTranslater;
using JsonTranslater.JsonModel;

public class WeatherController : ControllerBase
{
    #region 天气控制
    public SilverLining sunController;
    public ParticleSystem[] RainPars;
    public AudioSource audioS;

    //当天时间决定白天黑夜
    public int dayTime;

    //设置多云和阴天参数，亮度，云层位置
    public float Brightness;
    public Vector3 position;
#endregion
    

    //private void Start()
    //{
    //    SetDayOrNight(dayTime);
    //}
    

    public override void TranslateObj(object content)
    {
        int weatherIndex = (int)content;
        //一期，content内部为int参数，指定天气类型
        base.TranslateObj(content);
        //转int判断大小
        //11 - 19代表白天天气,(int)21-29代表黑夜天气
        SetDayOrNight(weatherIndex<20?14:23);
        switch (weatherIndex%10)
        {
            //晴天
            case 1:
                foreach (ParticleSystem temp in RainPars)
                {
                    temp.Play(true);
                }
                audioS.Play();
                InitCloudConfig(false,1,new Vector3(0,4000,0));
                break;
            //多云
            case 2:
                foreach (ParticleSystem temp in RainPars)
                {
                    temp.Play(true);
                }
                audioS.Play();
                InitCloudConfig(true, 1, new Vector3(0, 1500, 0));
                break;
            //雨
            case 3:
                foreach (ParticleSystem temp in RainPars)
                {
                    temp.Pause(true);
                }
                audioS.Pause();
                InitCloudConfig(true, 0.4f, new Vector3(0, 1300, 0));
                break;
               
        }

    }

    public void SetDayOrNight(int DayTime)
    {
        sunController.hour = DayTime;
    }

    //设置云层
    private void InitCloudConfig(bool hasCloud,float brightness,Vector3 position)
    {
        sunController.hasCumulusClouds = hasCloud;
        sunController.cumulusBrightness = brightness;
        sunController.cumulusPosition = position;
    }

    //设置当前时间
    private void InitDayOrNight(int dayTime)
    {
        sunController.day = dayTime;
    }
}
